<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>couchdb.multipart</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="couchdb-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="couchdb-module.html">Package&nbsp;couchdb</a> ::
        Module&nbsp;multipart
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
      </table>
    </td>
  </tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module multipart</h1><p class="nomargin-top"></p>
Support for streamed reading and writing of multipart MIME content.

<!-- ==================== FUNCTIONS ==================== -->
<a name="section-Functions"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Functions</span></td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="couchdb.multipart-module.html#read_multipart" class="summary-sig-name">read_multipart</a>(<span class="summary-sig-arg">fileobj</span>,
        <span class="summary-sig-arg">boundary</span>=<span class="summary-sig-default">None</span>)</span><br />
      Simple streaming MIME multipart parser.</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="couchdb.multipart-module.html#write_multipart" class="summary-sig-name">write_multipart</a>(<span class="summary-sig-arg">fileobj</span>,
        <span class="summary-sig-arg">subtype</span>=<span class="summary-sig-default"><code class="variable-quote">'</code><code class="variable-string">mixed</code><code class="variable-quote">'</code></span>,
        <span class="summary-sig-arg">boundary</span>=<span class="summary-sig-default">None</span>)</span><br />
      Simple streaming MIME multipart writer.</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
<!-- ==================== FUNCTION DETAILS ==================== -->
<a name="section-FunctionDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Function Details</span></td>
</tr>
</table>
<a name="read_multipart"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">read_multipart</span>(<span class="sig-arg">fileobj</span>,
        <span class="sig-arg">boundary</span>=<span class="sig-default">None</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  <p>Simple streaming MIME multipart parser.</p>
<p>This function takes a file-like object reading a MIME envelope, and yields
a <tt class="rst-docutils literal"><span class="pre">(headers,</span> <span class="pre">is_multipart,</span> <span class="pre">payload)</span></tt> tuple for every part found, where
<tt class="rst-docutils literal"><span class="pre">headers</span></tt> is a dictionary containing the MIME headers of that part (with
names lower-cased), <tt class="rst-docutils literal"><span class="pre">is_multipart</span></tt> is a boolean indicating whether the
part is itself multipart, and <tt class="rst-docutils literal"><span class="pre">payload</span></tt> is either a string (if
<tt class="rst-docutils literal"><span class="pre">is_multipart</span></tt> is false), or an iterator over the nested parts.</p>
<p>Note that the iterator produced for nested multipart payloads MUST be fully
consumed, even if you wish to skip over the content.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>fileobj</code></strong> - a file-like object</li>
        <li><strong class="pname"><code>boundary</code></strong> - the part boundary string, will generally be determined
automatically from the headers of the outermost multipart
envelope</li>
    </ul></dd>
    <dt>Returns:</dt>
        <dd>an iterator over the parts</dd>
  </dl>
<div class="fields">      <p><strong>Since:</strong>
        0.5
      </p>
</div></td></tr></table>
</div>
<a name="write_multipart"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">write_multipart</span>(<span class="sig-arg">fileobj</span>,
        <span class="sig-arg">subtype</span>=<span class="sig-default"><code class="variable-quote">'</code><code class="variable-string">mixed</code><code class="variable-quote">'</code></span>,
        <span class="sig-arg">boundary</span>=<span class="sig-default">None</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  <p>Simple streaming MIME multipart writer.</p>
<p>This function returns a MultipartWriter object that has a few methods to
control the nested MIME parts. For example, to write a flat multipart
envelope you call the <tt class="rst-docutils literal"><span class="pre">add(mimetype,</span> <span class="pre">content,</span> <span class="pre">[headers])</span></tt> method for
every part, and finally call the <tt class="rst-docutils literal"><span class="pre">close()</span></tt> method.</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">from</span> StringIO <span class="py-keyword">import</span> StringIO</pre>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>buf = StringIO()
<span class="py-prompt">&gt;&gt;&gt; </span>envelope = write_multipart(buf, boundary=<span class="py-string">'==123456789=='</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>envelope.add(<span class="py-string">'text/plain'</span>, <span class="py-string">'Just testing'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>envelope.close()
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">print</span> buf.getvalue().replace(<span class="py-string">'\r\n'</span>, <span class="py-string">'\n'</span>)
<span class="py-output">Content-Type: multipart/mixed; boundary=&quot;==123456789==&quot;</span>
<span class="py-output">&lt;BLANKLINE&gt;</span>
<span class="py-output">--==123456789==</span>
<span class="py-output">Content-Length: 12</span>
<span class="py-output">Content-MD5: nHmX4a6el41B06x2uCpglQ==</span>
<span class="py-output">Content-Type: text/plain</span>
<span class="py-output">&lt;BLANKLINE&gt;</span>
<span class="py-output">Just testing</span>
<span class="py-output">--==123456789==--</span>
<span class="py-output">&lt;BLANKLINE&gt;</span></pre>
<p>Note that an explicit boundary is only specified for testing purposes. If
the <code class="link">boundary</code> parameter is omitted, the multipart writer will generate a
random string for the boundary.</p>
<p>To write nested structures, call the <tt class="rst-docutils literal"><span class="pre">open([headers])</span></tt> method on the
respective envelope, and finish each envelope using the <tt class="rst-docutils literal"><span class="pre">close()</span></tt> method:</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>buf = StringIO()
<span class="py-prompt">&gt;&gt;&gt; </span>envelope = write_multipart(buf, boundary=<span class="py-string">'==123456789=='</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>part = envelope.open(boundary=<span class="py-string">'==abcdefghi=='</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>part.add(<span class="py-string">'text/plain'</span>, <span class="py-string">'Just testing'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>part.close()
<span class="py-prompt">&gt;&gt;&gt; </span>envelope.close()
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">print</span> buf.getvalue().replace(<span class="py-string">'\r\n'</span>, <span class="py-string">'\n'</span>) <span class="py-comment">#:doctest +ELLIPSIS</span>
<span class="py-output">Content-Type: multipart/mixed; boundary=&quot;==123456789==&quot;</span>
<span class="py-output">&lt;BLANKLINE&gt;</span>
<span class="py-output">--==123456789==</span>
<span class="py-output">Content-Type: multipart/mixed; boundary=&quot;==abcdefghi==&quot;</span>
<span class="py-output">&lt;BLANKLINE&gt;</span>
<span class="py-output">--==abcdefghi==</span>
<span class="py-output">Content-Length: 12</span>
<span class="py-output">Content-MD5: nHmX4a6el41B06x2uCpglQ==</span>
<span class="py-output">Content-Type: text/plain</span>
<span class="py-output">&lt;BLANKLINE&gt;</span>
<span class="py-output">Just testing</span>
<span class="py-output">--==abcdefghi==--</span>
<span class="py-output">--==123456789==--</span>
<span class="py-output">&lt;BLANKLINE&gt;</span></pre>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>fileobj</code></strong> - a writable file-like object that the output should get
written to</li>
        <li><strong class="pname"><code>subtype</code></strong> - the subtype of the multipart MIME type (e.g. &quot;mixed&quot;)</li>
        <li><strong class="pname"><code>boundary</code></strong> - the boundary to use to separate the different parts</li>
    </ul></dd>
  </dl>
<div class="fields">      <p><strong>Since:</strong>
        0.6
      </p>
</div></td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="couchdb-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Mon Dec 14 15:25:33 2009
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
